using System.ComponentModel.Design;
using PrismFactory.SoftwareFactory.Views.Properties;
using PrismFactory.SoftwareFactory.Views.Validators;

namespace PrismFactory.SoftwareFactory.Views.CreateModule
{
    public class CreateModulePageViewModel : ViewModelBase
    {
        public const string ModuleNamespaceKey = "ModuleNamespace";
//        public const string ShellProjectNameKey = "ShellProjectName";
//        public const string InfrastructureProjectNameKey = "InfrastructureProjectName";
//        public const string ShellTestProjectNameKey = "ShellTestProjectName";
//        public const string InfrastructureTestProjectNameKey = "InfrastructureTestProjectName";

        private readonly IDictionaryService dictionaryService;

        public CreateModulePageViewModel(IDictionaryService dictionaryService)
        {
            this.dictionaryService = dictionaryService;
            ValidatedProperties = new[]
                                      {
                                          ModuleNamespaceKey,
                                      };
//            UpdateProjectNames();
        }

        public string ModuleNamespace
        {
            get { return (string) dictionaryService.GetValue(ModuleNamespaceKey); }
            set
            {
                dictionaryService.SetValue(ModuleNamespaceKey, value);
//                UpdateProjectNames();
                OnPropertyChanged(ModuleNamespaceKey);
            }
        }

//        public string ShellProjectName
//        {
//            get { return (string) dictionaryService.GetValue(ShellProjectNameKey); }
//            private set
//            {
//                dictionaryService.SetValue(ShellProjectNameKey, value);
//                OnPropertyChanged(ShellProjectNameKey);
//            }
//        }
//
//        public string InfrastructureProjectName
//        {
//            get { return (string) dictionaryService.GetValue(InfrastructureProjectNameKey); }
//            private set
//            {
//                dictionaryService.SetValue(InfrastructureProjectNameKey, value);
//                OnPropertyChanged(InfrastructureProjectNameKey);
//            }
//        }
//
//        public string ShellTestProjectName
//        {
//            get { return (string) dictionaryService.GetValue(ShellTestProjectNameKey); }
//            private set
//            {
//                dictionaryService.SetValue(ShellTestProjectNameKey, value);
//                OnPropertyChanged(ShellTestProjectNameKey);
//            }
//        }
//
//        public string InfrastructureTestProjectName
//        {
//            get { return (string) dictionaryService.GetValue(InfrastructureTestProjectNameKey); }
//            private set
//            {
//                dictionaryService.SetValue(InfrastructureTestProjectNameKey, value);
//                OnPropertyChanged(InfrastructureTestProjectNameKey);
//            }
//        }
//
//        private void UpdateProjectNames()
//        {
//            ShellProjectName = BuildShellProjectName();
//            InfrastructureProjectName = BuildInfrastructureProjectName();
//            ShellTestProjectName = BuildShellTestProjectName();
//            InfrastructureTestProjectName = BuildInfrastructureTestProjectName();
//        }
//
//        private string BuildInfrastructureProjectName()
//        {
//            return RootNamespace + ".Infrastructure";
//        }
//
//        private string BuildShellProjectName()
//        {
//            return RootNamespace + ".Shell";
//        }
//
//        private string BuildInfrastructureTestProjectName()
//        {
//            return BuildInfrastructureProjectName() + ".Tests";
//        }
//
//        private string BuildShellTestProjectName()
//        {
//            return BuildShellProjectName() + ".Tests";
//        }

        protected override void DoPropertyValidation(string propertyName, ref string error)
        {
            switch (propertyName)
            {
                case ModuleNamespaceKey:
                    var namespaceValidator = new NamespaceValidator();
                    if (!namespaceValidator.Validate(ModuleNamespace).IsValid)
                        error = Resources.InvalidNamespace;
                    break;
            }
        }
    }
}